package com.woniu.components.DAO;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: xujin
 * Date: 2010-3-1
 * Time: 20:49:42
 * To change this template use File | Settings | File Templates.
 */
public class DisPage implements Serializable {
    private static final long serialVersionUID = -4684071708405300042L;
    private Integer pageSize = 20;
    private Integer startNum = 0;
    private Integer currentPage = null;
    private Long totalPages;
    private Long totalRows;

    public DisPage() {

    }

    public DisPage(Integer startNum, Integer pageSize) {
        this.startNum = startNum;
        this.pageSize = pageSize;
    }

    public DisPage(String startNum, String pageSize) {
        this.startNum = Integer.getInteger(startNum);
        this.pageSize = Integer.getInteger(pageSize);
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setStartNum(Integer startNum) {
        this.startNum = startNum;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getCurrentPage() {
        if (this.currentPage == null) {
            this.currentPage = this.startNum / this.pageSize + 1;
        }
        return this.currentPage;
    }

    public void setTotalPage(Long totalPageCount) {
        this.totalPages = totalPageCount;
    }

    public void setTotalRow(Long totalRowCount) {
        this.totalRows = totalRowCount;
        this.totalPages = (totalRowCount + this.pageSize - 1) / this.pageSize;
    }
 
    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getStartNum() {
        return startNum;
    }

    public Long getTotalPages() {
        return totalPages;
    }

    public Long getTotalRows() {
        return totalRows;
    }

    public static DisPage getIsDisPage(String start, String limit) {
        if (start == null || "".equals(start.trim())) {
            return null;
        }

        if ((limit == null || "".equals(limit.trim()))) {
            return new DisPage(start, "20");
        }
        
        return new DisPage(start, limit);

    }
}
